package com.zhongyouyun.web.controller;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zhongyouyun.admin.model.DisplayMainModel;
import com.zhongyouyun.admin.model.MsgModel;
import com.zhongyouyun.admin.model.RoleModel;
import com.zhongyouyun.admin.model.SiteListModel;
import com.zhongyouyun.admin.service.MsgService;
import com.zhongyouyun.other.model.PageRequest;
import com.zhongyouyun.other.model.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;

@Controller
@RequestMapping("/web/toDoAndMsg")
@Api(value = "物资通知或待办", tags = {"物资通知或待办"})
public class ToDoAndMsgController {

    @Autowired
    private MsgService service;

    @PostMapping("/getToDo")
    @ResponseBody
    @ApiOperation(value = "获取待办", notes = "获取待办")
    @ApiResponses({
            @ApiResponse(code=0,message = "操作成功",response = RoleModel.class)
    })
    public Result<List<MsgModel>> getToDo(String user) {
        if(ObjectUtil.isNotEmpty(user)){
            QueryWrapper queryWrapper = new QueryWrapper();
            queryWrapper.eq("target",user);
            queryWrapper.eq("type","todo");
            List<MsgModel> msgModels = service.selectList(queryWrapper);
            return  Result.<List<MsgModel>>builder().message("成功").status(0).data(msgModels).build();
        }else{
            return Result.<List<MsgModel>>builder().message("用户未登录").status(1).build();
        }
    }

    @PostMapping("/getUnMsg")
    @ResponseBody
    @ApiOperation(value = "获取未读通知", notes = "获取未读通知")
    @ApiResponses({
            @ApiResponse(code=0,message = "操作成功",response = RoleModel.class)
    })
    public Result<List<MsgModel>> getUnMsg(String user) {
        if(ObjectUtil.isNotEmpty(user)){
            QueryWrapper queryWrapper = new QueryWrapper();
            queryWrapper.eq("target",user);
            queryWrapper.eq("type","msg");
            List<MsgModel> msgModels = service.selectList(queryWrapper);
            return  Result.<List<MsgModel>>builder().message("成功").status(0).data(msgModels).build();
        }else{
            return Result.<List<MsgModel>>builder().message("用户未登录").status(1).build();
        }
    }

    @PostMapping("/ReadMsg")
    @ResponseBody
    @ApiOperation(value = "获取未读通知", notes = "获取未读通知")
    @ApiResponses({
            @ApiResponse(code=0,message = "操作成功",response = RoleModel.class)
    })
    public Result<List<MsgModel>> ReadMsg(@RequestBody MsgModel msgModel) {
        if(ObjectUtil.isNotEmpty(msgModel)){

            return  Result.<List<MsgModel>>builder().message("成功").status(0).data(new ArrayList<>()).build();
        }else{
            return Result.<List<MsgModel>>builder().message("获取信息失败").status(1).build();
        }
    }
}
